//
//  LFAccountOrderStateViewController.m
//  LoveFruit
//
//  Created by 刘栋 on 16/9/25.
//  Copyright © 2016年 张令林. All rights reserved.
//

#import "LFAccountOrderStateViewController.h"

#import "LFOrderStateViewCell.h"
#import "LFAccountOrderModel.h"

static NSString *cellId = @"cellId";

@interface LFAccountOrderStateViewController () <UITableViewDataSource,UITableViewDelegate>

@property (nonatomic,strong) NSMutableArray *dataArray;

@property (nonatomic,weak) UITableView *tableView;

@end

@implementation LFAccountOrderStateViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor yellowColor];
    
    [self createTableView];
    
    [self loadData];
}

- (void)loadData
{
    LFAccountOrderModel *model = [LFAccountOrderModel new];
    
    model.title = @"订单已取消";
    model.time = @"2016-09-25 15:45";
    model.flag = 1;
    
    LFAccountOrderModel *model1 = [LFAccountOrderModel new];
    
    model1.title = @"待支付";
    model1.desc = @"超过1小时未支付订单将自动取消";
    model1.time = @"2016-09-25 14:44";
    model1.flag = 0;
    
    LFAccountOrderModel *model2 = [LFAccountOrderModel new];
    
    model2.title = @"订单提交成功";
    model2.desc = @"下单成功,订单号:a001z20160925";
    model2.detail = @"配送时间:09月26日 10:00-20:00";
    model2.time = @"2016-09-25 14:44";
    model2.flag = 0;
    
    [self.dataArray addObject:model];
    [self.dataArray addObject:model1];
    [self.dataArray addObject:model2];
    [self.tableView reloadData];
}

- (NSMutableArray *)dataArray
{
   if(_dataArray == nil)
   {
       _dataArray = [NSMutableArray array];
   }
    return _dataArray;
}

- (void)createTableView
{
    UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
    tableView.dataSource = self;
    tableView.delegate = self;
    
    [self.view addSubview:tableView];
    
//    tableView.rowHeight = 150;
    self.tableView = tableView;
    
    tableView.tableFooterView = [[UIView alloc] init];
    
    tableView.estimatedRowHeight = 100;
    tableView.rowHeight = UITableViewAutomaticDimension;
    
    //注册cell
    [tableView registerNib:[UINib nibWithNibName:@"LFOrderStateViewCell" bundle:nil] forCellReuseIdentifier:cellId];
    
    //设置cell的约束
    [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.edges.equalTo(self.view);
        
    }];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    LFOrderStateViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId forIndexPath:indexPath];
    if(cell == nil)
    {
        cell = [[LFOrderStateViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellId];
    }
    
    LFAccountOrderModel *accountModel = self.dataArray[indexPath.row];
    
    cell.orderModel = accountModel;
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
